﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Willows.PreliminaryModel
{
	public class HierarchicalName
	{
		private Stack<string> stack = new Stack<string>();

		public void Push(string name)
		{
			stack.Push(name);
		}

		public void Pop()
		{
			stack.Pop();
		}

		public string GetName()
		{
			StringBuilder str = new StringBuilder();

			Stack<string> tmp = new Stack<string>();
			// reverse stack
			foreach (string name in stack)
				tmp.Push(name);

			foreach (string name in tmp)
				str.Append(name + ".");

			// remove the last '.'
			str.Remove(str.Length - 1, 1);

			return str.ToString();
		}

		public string CreateUniqueName(string localName)
		{
			return GetName().Replace(".", "_") + "_" + localName;
		}

		public string CreateUniqueName()
		{
			return GetName().Replace(".", "_");
		}

		public HierarchicalName()
		{
		}
	}
}
